package net.huashitong.Indicators.web;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sirdc.modules.core.web.JsonBaseController;
import com.sirdc.modules.core.web.model.Message;
import com.sirdc.modules.utils.ObjectUtils;

import net.huashitong.Indicators.databean.IndicatorBreakdownDatabean;
import net.huashitong.Indicators.entity.TertiaryIndustry;
import net.huashitong.Indicators.filter.IndicatorBreakdownFilter;
import net.huashitong.Indicators.service.GaugeIndustryService;
import net.huashitong.Indicators.service.GaugeIndustryTotalService;
import net.huashitong.Indicators.service.TertiaryIndustryService;
import net.huashitong.Indicators.utils.CodeUtils;
import net.huashitong.Indicators.utils.DateForIndUtils;
import net.huashitong.Indicators.utils.ThiTitleUtils;
import net.huashitong.scheduling.utils.IsUserUtils;
@Controller
@RequestMapping("/app/gaugeIndustryTotal")
public class GaugeIndustryTotalAppController extends JsonBaseController {
	@Autowired
	private GaugeIndustryTotalService gaugeIndustryTotalService;
	@Autowired
	private TertiaryIndustryService industryService;
	@Override
	protected String getView(String arg0) {
		// TODO Auto-generated method stub
		return null;
	}
	@RequestMapping("/queryGSGYSecView")
	@ResponseBody
	public Message queryGSGYSecView(@RequestBody IndicatorBreakdownFilter filter) throws ParseException{
		String date = DateForIndUtils.getMonth(filter.getDate());
		IsUserUtils isuts=new IsUserUtils();
		String cuDate = DateForIndUtils.getCMonth(filter.getDate());
		filter.setDate(date);
		filter.setCurrentMonth(cuDate);
		List<Map<String, Object>> maps = new ArrayList<Map<String,Object>>();
		Map<String, Object> map = new HashMap<String, Object>();
		//规模以上工业产值全市各县区排名情况
		IndicatorBreakdownDatabean databean = gaugeIndustryTotalService.queryCountyRank(filter);
		if(ObjectUtils.isNotBlank(databean)){
			map.put("type", "1");
			map.put("dataInner", databean);
			map.put("unit", "亿元");
			map.put("monthOrQuarter", CodeUtils.monthOrQuarter_mon);
			map.put("descOne", date.substring(0, 4)+ThiTitleUtils.GXQZZL);
			map.put("descTwo", date.substring(0, 4)+ThiTitleUtils.GXQJDZ);
			map.put("title", "该指标全市排名一览");
			map.put("secTitle", "规模以上工业产值全市各县区排名情况");
			maps.add(map);
		}
		
		// 规模以上工业产值当月同比增长情况
	    filter.setDate(date);
	    List<IndicatorBreakdownDatabean> databeans = gaugeIndustryTotalService.queryDevelopmentSituation(filter);
	    if(ObjectUtils.isNotBlank(databeans)){
					map = new HashMap<String, Object>();
					map.put("type", "2");
					map.put("data", databeans);
					map.put("descOne", ThiTitleUtils.DYTBZZL);
					map.put("descTwo", ThiTitleUtils.DYLJZZL);
					map.put("monthOrQuarter", CodeUtils.monthOrQuarter_mon);
					map.put("title", "该指标发展情况");
					map.put("secTitle", "规模以上工业产值增长情况");
					maps.add(map);
		 }
	    map = new HashMap<String, Object>();
		filter.setCurrentMonth(cuDate);
	    TertiaryIndustry industry = industryService.queryByfilter(filter);
	    if(ObjectUtils.isNotBlank(industry)){
	    	map.put("leadership", industry.getLeadership());
	 		map.put("unitsNumber", industry.getUnitsNumber());
	    }
		map.put("monthOrQuarter", CodeUtils.monthOrQuarter_mon);
		map.put("lists", maps);
		map.put("title", "规模以上工业产值运行情况");
		  return coverMessage("200", "数据获取成功", map);
	}
	
	
}
